package com.dzk.cp.c11x5.catcher.task;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dzk.cp.c11x5.catcher.CodeCatcherService;
import com.dzk.cp.c11x5.constant.C11x5Constants;
import com.dzk.cp.c11x5.pojo.GdR5;
import com.dzk.cp.c11x5.service.R5Service;
import com.dzk.cp.util.DateUtils;
import com.dzk.cp.util.PropsUtils;

@Component("gdCodeCatcherTask")
public class GdCodeCatcherTask extends CodeCatcherTask<GdR5> {
	
	private static final Logger log = Logger.getLogger(GdCodeCatcherTask.class);
	
	@Resource(name="gdR5Service")
	private R5Service<GdR5> r5Service;
	
	@Resource(name="gdCodeCatcherService")
	private CodeCatcherService<GdR5> codeCatcherService;
	
	protected void doCatchCode() {
		log.info("抓取数据ByIssue......");
		String fromIssue = DateUtils.dateToStr(new Date(), "yyyyMMdd") + "01";
		if (r5Service.getR5ByQs(fromIssue) != null) {
			GdR5 r5 = r5Service.getLastR5();
			fromIssue = Integer.valueOf(r5.getQs()) + 1 + "";
		}
		String toIssue = super.getCurrentIssue(PropsUtils.getProperty(C11x5Constants.GD11X5_SALETIME_FROM), 
				Integer.valueOf(PropsUtils.getProperty(C11x5Constants.GD11X5_INTERVAL)));
		String issues = super.getIssues(fromIssue, toIssue);
		log.info("抓取数据issues=" + issues);
		if (issues.length() > 0) {
			codeCatcherService.catchCodeByIssue(issues);
		}
		log.info("抓取数据ByIssue...end");
	}

}
